#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    string str;
    vector<string> s, d;
    int n, ct = 0, flag = 0;
    char c;
    scanf("%c %d", &c, &n);
    getchar();
    for (int i = 0;i < n;i++)
    {
        getline(cin, str);
        string::iterator it = str.begin();
        for (int j = 0;j < str.size();j++)
        {
            if (str[j] != ' ')
            {
                str[j] = c;
            }
        }
        s.push_back(str);
        reverse(str.begin(), str.end());
        d.push_back(str);
    }
    for(int i = 0;i<n;i++)
    {
        if (d[i] == s[i])
        {
            flag++;
        }
    }
    if (flag == n)
    {
        cout << "bu yong dao le" << endl;
        for (int i = 0;i < s.size();i++)
        {
            cout << s[i] << endl;
        }
    }
    else{
        for (int i = s.size() - 1;i >= 0;i--)
        {
            cout << d[i] << endl;
        }
    }
    return 0;
}
